﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace VodafoneWP7
{
    public class MessageItemViewModel : INotifyPropertyChanged
    {
        private string _destination;
        public Message related_message;
        public Account related_acount;
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
        /// </summary>
        /// <returns></returns>
        public string Destination
        {
            get
            {
                return _destination;
            }
            set
            {
                if (value != _destination)
                {
                    _destination = value;
                    NotifyPropertyChanged("Destination");
                }
            }
        }

        public bool short_message = true;
        private string _message;
        private string _mess;
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
        /// </summary>
        /// <returns></returns>
        public string Message
        {
            get
            {
                return short_message?_mess:_message;
            }
            set
            {
                if (value != _message)
                {
                    _message = value;
                    var first_return = _message.IndexOf('\n');
                    first_return = first_return == -1 ? _message.Length : first_return;
                    var num_char = Math.Min(Width / 9, first_return);
                    _mess = _message.Length <= num_char ? _message : _message.Substring(0, num_char) + "...";
                    NotifyPropertyChanged("Message");
                }
            }
        }


        public bool delete = false;
        public string Delete
        {
            get
            {
                return delete ? "Red" : "Transparent";
            }
        }

        public bool deleting = false;
        public string ColumnWidth
        {
            get
            {
                return deleting ? "70" : "0";
            }
        }

        public string CheckVisibility
        {
            get
            {
                return deleting ? "Visible" : "Collapsed";
            }
        }

        public int Width
        {
            get { return LayoutConfiguration.MessagesListWidth; }
        }
        
        private string _date;
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
        /// </summary>
        /// <returns></returns>
        public string Date
        {
            get
            {
                return _date;
            }
            set
            {
                if (value != _date)
                {
                    _date = value;
                    NotifyPropertyChanged("Date");
                }
            }
        }

        private string _service;
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
        /// </summary>
        /// <returns></returns>
        public string Service
        {
            get
            {
                return _service;
            }
            set
            {
                if (value != _service)
                {
                    _service = value;
                    NotifyPropertyChanged("Service");
                }
            }
        }

        private string _type;
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding.
        /// </summary>
        /// <returns></returns>
        public string Type
        {
            get
            {
                return _type;
            }
            set
            {
                if (value != _type)
                {
                    _type = value;
                    NotifyPropertyChanged("Type");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}